home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-blog-header.php < prev    next >
Encoding:
PHP Script  |  2004-12-16  |  18.7 KB  |  534 lines

  1. <?php
  2.  
  3. if (!file_exists(dirname(__FILE__).'/' . 'wp-config.php'))
  4.     die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='wp-admin/setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.");
  5.  
  6. require_once(dirname(__FILE__).'/' . '/wp-config.php');
  7.  
  8. require_once(dirname(__FILE__).'/' . 'wp-includes/wp-l10n.php');
  9.  
  10. // Process PATH_INFO, if set.
  11. $path_info = array();
  12. if (! empty($_SERVER['PATH_INFO'])) {
  13.     // Fetch the rewrite rules.
  14.     $rewrite = rewrite_rules('matches');
  15.  
  16.     $pathinfo = $_SERVER['PATH_INFO'];
  17.     // Trim leading '/'.
  18.     $pathinfo = preg_replace("!^/!", '', $pathinfo);
  19.  
  20.     if (! empty($rewrite)) {
  21.         // Get the name of the file requesting path info.
  22.         $req_uri = $_SERVER['REQUEST_URI'];
  23.         $req_uri = str_replace($pathinfo, '', $req_uri);
  24.         $req_uri = preg_replace("!/+$!", '', $req_uri);
  25.         $req_uri = explode('/', $req_uri);
  26.         $req_uri = $req_uri[count($req_uri)-1];
  27.  
  28.         // Look for matches.
  29.         $pathinfomatch = $pathinfo;
  30.         foreach ($rewrite as $match => $query) {
  31.             // If the request URI is the anchor of the match, prepend it
  32.             // to the path info.
  33.             if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0)) {
  34.                 $pathinfomatch = $req_uri . '/' . $pathinfo;
  35.             }
  36.  
  37.             if (preg_match("!^$match!", $pathinfomatch, $matches)) {
  38.                 // Got a match.
  39.                 // Trim the query of everything up to the '?'.
  40.                 $query = preg_replace("!^.+\?!", '', $query);
  41.  
  42.                 // Substitute the substring matches into the query.
  43.                 eval("\$query = \"$query\";");
  44.  
  45.                 // Parse the query.
  46.                 parse_str($query, $path_info);
  47.             }
  48.         }
  49.     }    
  50. }
  51.  
  52. $wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name');
  53.  
  54.     for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  55.         $wpvar = $wpvarstoreset[$i];
  56.         if (!isset($$wpvar)) {
  57.             if (empty($_POST[$wpvar])) {
  58.                 if (empty($_GET[$wpvar]) && empty($path_info[$wpvar])) {
  59.                     $$wpvar = '';
  60.                 } elseif (!empty($_GET[$wpvar])) {
  61.                     $$wpvar = $_GET[$wpvar];
  62.                 } else {
  63.                     $$wpvar = $path_info[$wpvar];
  64.                 }
  65.             } else {
  66.                 $$wpvar = $_POST[$wpvar];
  67.             }
  68.         }
  69.     }
  70.  
  71.  
  72. // Sending HTTP headers
  73.  
  74. if (!isset($doing_rss) || !$doing_rss) {
  75.     // It is presumptious to think that WP is the only thing that might change on the page.
  76.     @header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                 // Date in the past
  77.     @header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
  78.     @header("Cache-Control: no-store, no-cache, must-revalidate");     // HTTP/1.1
  79.     @header("Cache-Control: post-check=0, pre-check=0", false);
  80.     @header("Pragma: no-cache");                                     // HTTP/1.0
  81.     @header ('X-Pingback: '. get_settings('siteurl') . '/xmlrpc.php');
  82. } else {
  83.  
  84.     // We're showing a feed, so WP is indeed the only thing that last changed
  85.     $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
  86.     $wp_etag = '"'.md5($wp_last_modified).'"';
  87.     @header('Last-Modified: '.$wp_last_modified);
  88.     @header('ETag: '.$wp_etag);
  89.     @header ('X-Pingback: ' . get_settings('siteurl') . '/xmlrpc.php');
  90.  
  91.     // Support for Conditional GET
  92.     if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) $client_last_modified = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
  93.     else $client_last_modified = false;
  94.     if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
  95.     else $client_etag = false;
  96.  
  97.     if ( ($client_last_modified && $client_etag) ?
  98.         (($client_last_modified == $wp_last_modified) && ($client_etag == $wp_etag)) :
  99.         (($client_last_modified == $wp_last_modified) || ($client_etag == $wp_etag)) ) {
  100.         if ( preg_match('/cgi/',php_sapi_name()) ) {
  101.             header('HTTP/1.1 304 Not Modified');
  102.             echo "\r\n\r\n";
  103.             exit;
  104.         } else {
  105.             if (version_compare(phpversion(),'4.3.0','>=')) {
  106.                 header('Not Modified', TRUE, 304);
  107.             } else {
  108.                 header('HTTP/1.x 304 Not Modified');
  109.             }
  110.         }
  111.     }
  112.  
  113. }
  114.  
  115. // Getting settings from DB
  116. if (isset($doing_rss) && $doing_rss == 1)
  117.     $posts_per_page=get_settings('posts_per_rss');
  118. if (!isset($posts_per_page) || $posts_per_page == 0)
  119.     $posts_per_page = get_settings('posts_per_page');
  120. if (!isset($what_to_show))
  121.     $what_to_show = get_settings('what_to_show');
  122. $archive_mode = get_settings('archive_mode');
  123. $use_gzipcompression = get_settings('gzipcompression');
  124.  
  125. // First let's clear some variables
  126. $whichcat = '';
  127. $whichauthor = '';
  128. $result = '';
  129. $where = '';
  130. $limits = '';
  131. $distinct = '';
  132. $join = '';
  133.  
  134. if ($pagenow != 'post.php') { timer_start(); }
  135.  
  136. if (isset($showposts) && $showposts) {
  137.     $showposts = (int)$showposts;
  138.     $posts_per_page = $showposts;
  139. }
  140.  
  141. $add_hours = intval(get_settings('gmt_offset'));
  142. $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
  143. $wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)";
  144.  
  145. // If a month is specified in the querystring, load that month
  146. if ('' != $m) {
  147.     $m = '' . preg_replace('|[^0-9]|', '', $m);
  148.     $where .= ' AND YEAR(post_date)=' . substr($m, 0, 4);
  149.     if (strlen($m)>5)
  150.         $where .= ' AND MONTH(post_date)=' . substr($m, 4, 2);
  151.     if (strlen($m)>7)
  152.         $where .= ' AND DAYOFMONTH(post_date)=' . substr($m, 6, 2);
  153.     if (strlen($m)>9)
  154.         $where .= ' AND HOUR(post_date)=' . substr($m, 8, 2);
  155.     if (strlen($m)>11)
  156.         $where .= ' AND MINUTE(post_date)=' . substr($m, 10, 2);
  157.     if (strlen($m)>13)
  158.         $where .= ' AND SECOND(post_date)=' . substr($m, 12, 2);
  159. }
  160.  
  161. if ('' != $hour) {
  162.     $hour = '' . intval($hour);
  163.     $where .= " AND HOUR(post_date)='$hour'";
  164. }
  165.  
  166. if ('' != $minute) {
  167.     $minute = '' . intval($minute);
  168.     $where .= " AND MINUTE(post_date)='$minute'";
  169. }
  170.  
  171. if ('' != $second) {
  172.     $second = '' . intval($second);
  173.     $where .= " AND SECOND(post_date)='$second'";
  174. }
  175.  
  176. if ('' != $year) {
  177.     $year = '' . intval($year);
  178.     $where .= " AND YEAR(post_date)='$year'";
  179. }
  180.  
  181. if ('' != $monthnum) {
  182.     $monthnum = '' . intval($monthnum);
  183.     $where .= " AND MONTH(post_date)='$monthnum'";
  184. }
  185.  
  186. if ('' != $day) {
  187.     $day = '' . intval($day);
  188.     $where .= " AND DAYOFMONTH(post_date)='$day'";
  189. }
  190.  
  191. if ('' != $name) {
  192.     $name = preg_replace('/[^a-z0-9-_]/', '', $name);
  193.     $where .= " AND post_name = '$name'";
  194. }
  195.  
  196. if ('' != $w) {
  197.     $w = ''.intval($w);
  198.     $where .= " AND WEEK(post_date, 1)='$w'";
  199. }
  200.  
  201. // If a post number is specified, load that post
  202. if (($p != '') && ($p != 'all')) {
  203.     $p = intval($p);
  204.     $where = ' AND ID = '.$p;
  205. }
  206.  
  207. // If a search pattern is specified, load the posts that match
  208. if (!empty($s)) {
  209.     $s = addslashes_gpc($s);
  210.     $search = ' AND (';
  211.     $s = preg_replace('/, +/', ' ', $s);
  212.     $s = str_replace(',', ' ', $s);
  213.     $s = str_replace('"', ' ', $s);
  214.     $s = trim($s);
  215.     if ($exact) {
  216.         $n = '';
  217.     } else {
  218.         $n = '%';
  219.     }
  220.     if (!$sentence) {
  221.         $s_array = explode(' ',$s);
  222.         $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
  223.         for ( $i = 1; $i < count($s_array); $i = $i + 1) {
  224.             $search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
  225.         }
  226.         $search .= ' OR (post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\')';
  227.         $search .= ')';
  228.     } else {
  229.         $search = ' AND ((post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\'))';
  230.     }
  231. }
  232.  
  233. // Category stuff
  234. $dogs = $wpdb->get_results("SELECT * FROM $tablecategories WHERE 1=1");
  235. foreach ($dogs as $catt) {
  236.     $cache_categories[$catt->cat_ID] = $catt;
  237. }
  238.  
  239. if ((empty($cat)) || ($cat == 'all') || ($cat == '0') || 
  240.     // Bypass cat checks if fetching specific posts
  241.     (
  242.         intval($year) || intval($monthnum) || intval($day) || intval($w) ||
  243.         intval($p) || !empty($name) || !empty($s)
  244.     )
  245.         ) {
  246.     $whichcat='';
  247. } else {
  248.     $cat = ''.urldecode($cat).'';
  249.     $cat = addslashes_gpc($cat);
  250.     if (stristr($cat,'-')) {
  251.         // Note: if we have a negative, we ignore all the positives. It must
  252.         // always mean 'everything /except/ this one'. We should be able to do
  253.         // multiple negatives but we don't :-(
  254.         $eq = '!=';
  255.         $andor = 'AND';
  256.         $cat = explode('-',$cat);
  257.         $cat = intval($cat[1]);
  258.     } else {
  259.         $eq = '=';
  260.         $andor = 'OR';
  261.     }
  262.     $join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) ";
  263.     $cat_array = explode(' ',$cat);
  264.     $whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]);
  265.     $whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' ');
  266.     for ($i = 1; $i < (count($cat_array)); $i = $i + 1) {
  267.             $whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]);
  268.         $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' ');
  269.     }
  270.     $whichcat .= ')';
  271.     if ($eq == '!=') {
  272.         $cat = '-'.$cat; // Put back the knowledge that we are excluding a category.
  273.     }
  274. }
  275.  
  276. // Category stuff for nice URIs
  277.  
  278. if ('' != $category_name) {
  279.     if (stristr($category_name,'/')) {
  280.         $category_name = explode('/',$category_name);
  281.         if ($category_name[count($category_name)-1]) {
  282.         $category_name = $category_name[count($category_name)-1]; // no trailing slash
  283.         } else {
  284.         $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
  285.         }
  286.     }
  287.     $category_name = preg_replace('|[^a-z0-9-_]|i', '', $category_name);
  288.     $tables = ", $tablepost2cat, $tablecategories";
  289.     $join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
  290.     $whichcat = " AND (category_nicename = '$category_name'";
  291.     $cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'");
  292.     $whichcat .= get_category_children($cat, " OR category_id = ");
  293.     $whichcat .= ")";
  294. }
  295.  
  296. // Author/user stuff
  297. $users = $wpdb->get_results("SELECT * FROM $tableusers WHERE user_level > 0");
  298. foreach ($users as $user) {
  299.     $cache_userdata[$user->ID] = $user;
  300. }
  301.  
  302. if ((empty($author)) || ($author == 'all') || ($author == '0')) {
  303.     $whichauthor='';
  304. } else {
  305.     $author = ''.urldecode($author).'';
  306.     $author = addslashes_gpc($author);
  307.     if (stristr($author, '-')) {
  308.         $eq = '!=';
  309.         $andor = 'AND';
  310.         $author = explode('-', $author);
  311.         $author = ''.intval($author[1]);
  312.     } else {
  313.         $eq = '=';
  314.         $andor = 'OR';
  315.     }
  316.     $author_array = explode(' ', $author);
  317.     $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);
  318.     for ($i = 1; $i < (count($author_array)); $i = $i + 1) {
  319.         $whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);
  320.     }
  321.     $whichauthor .= ')';
  322. }
  323.  
  324. // Author stuff for nice URIs
  325.  
  326. if ('' != $author_name) {
  327.     if (stristr($author_name,'/')) {
  328.         $author_name = explode('/',$author_name);
  329.         if ($author_name[count($author_name)-1]) {
  330.         $author_name = $author_name[count($author_name)-1];#no trailing slash
  331.         } else {
  332.         $author_name = $author_name[count($author_name)-2];#there was a trailling slash
  333.         }
  334.     }
  335.     $author_name = preg_replace('|[^a-z0-9-_]|', '', strtolower($author_name));
  336.     $author = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_nicename='".$author_name."'");
  337.     $whichauthor .= ' AND (post_author = '.intval($author).')';
  338. }
  339.  
  340. $where .= $search.$whichcat.$whichauthor;
  341.  
  342. if ((empty($order)) || ((strtoupper($order) != 'ASC') && (strtoupper($order) != 'DESC'))) {
  343.     $order='DESC';
  344. }
  345.  
  346. // Order by
  347. if (empty($orderby)) {
  348.     $orderby='date '.$order;
  349. } else {
  350.     // Used to filter values
  351.     $allowed_keys = array('author','date','category','title');
  352.     $orderby = urldecode($orderby);
  353.     $orderby = addslashes_gpc($orderby);
  354.     $orderby_array = explode(' ',$orderby);
  355.     if (!in_array($orderby_array[0],$allowed_keys)) {
  356.         $orderby_array[0] = 'date';
  357.     }
  358.     $orderby = $orderby_array[0].' '.$order;
  359.     if (count($orderby_array)>1) {
  360.         for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) {
  361.             // Only allow certain values for safety
  362.             if (in_array($orderby_array[$i],$allowed_keys)) {
  363.                 $orderby .= ',post_'.$orderby_array[$i].' '.$order;
  364.             }
  365.         }
  366.     }
  367. }
  368.  
  369. if ((!$whichcat) && (!$m) && (!$p) && (!$w) && (!$s) && empty($poststart) && empty($postend)) {
  370.     if ($what_to_show == 'posts') {
  371.         $limits = ' LIMIT '.$posts_per_page;
  372.     } elseif ($what_to_show == 'days' && empty($monthnum) && empty($year) && empty($day)) {
  373.         $lastpostdate = get_lastpostdate();
  374.         $lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
  375.         $lastpostdate = mysql2date('U',$lastpostdate);
  376.         $otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($posts_per_page-1) * 86400)));
  377.         $where .= " AND post_date > '$otherdate'";
  378.     }
  379. }
  380.  
  381. if ( !empty($postend) && ($postend > $poststart) && (!$m) && empty($monthnum) && empty($year) && empty($day) &&(!$w) && (!$whichcat) && (!$s) && (!$p)) {
  382.     if ($what_to_show == 'posts' || ($what_to_show == 'paged' && (!$paged))) {
  383.         $poststart = intval($poststart);
  384.         $postend = intval($postend);
  385.         $limposts = $postend - $poststart;
  386.         $limits = ' LIMIT '.$poststart.','.$limposts;
  387.     } elseif ($what_to_show == 'days') {
  388.         $poststart = intval($poststart);
  389.         $postend = intval($postend);
  390.         $limposts = $postend - $poststart;
  391.         $lastpostdate = get_lastpostdate();
  392.         $lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
  393.         $lastpostdate = mysql2date('U',$lastpostdate);
  394.         $startdate = date('Y-m-d H:i:s', ($lastpostdate - (($poststart -1) * 86400)));
  395.         $otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($postend -1) * 86400)));
  396.         $where .= " AND post_date > '$otherdate' AND post_date < '$startdate'";
  397.     }
  398. } else {
  399.     if (($what_to_show == 'paged') && (!$p) && (!$more)) {
  400.         if ($pagenow != 'post.php') {
  401.             $pgstrt = '';
  402.             if ($paged) {
  403.                 $pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
  404.             }
  405.             $limits = 'LIMIT '.$pgstrt.$posts_per_page;
  406.         } else {
  407.             if (($m) || ($p) || ($w) || ($s) || ($whichcat)) {
  408.                 $limits = '';
  409.             } else {
  410.                 $pgstrt = '';
  411.                 if ($paged) {
  412.                     $pgstrt = (intval($paged) -1) * $posts_per_page . ', ';
  413.                 }
  414.                 $limits = 'LIMIT '.$pgstrt.$posts_per_page;
  415.             }
  416.         }
  417.     }
  418.     elseif (($m) || ($p) || ($w) || ($s) || ($whichcat) || ($author) || $monthnum || $year || $day) {
  419.         $limits = '';
  420.     }
  421. }
  422.  
  423. if ($p == 'all') {
  424.     $where = '';
  425. }
  426.  
  427. $now = gmdate('Y-m-d H:i:59');
  428.  
  429. if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
  430.     if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) {
  431.         $where .= " AND post_date_gmt <= '$now'";
  432.     }
  433.  
  434.     $distinct = 'DISTINCT';
  435.  
  436.     if ($use_gzipcompression) {
  437.         // gzipping the output of the script
  438.         gzip_compression();
  439.     }
  440. }
  441. $where .= ' AND (post_status = "publish"';
  442.  
  443. // Get private posts
  444. if (isset($user_ID) && ('' != intval($user_ID)))
  445.     $where .= " OR post_author = $user_ID AND post_status != 'draft')";
  446. else
  447.     $where .= ')';
  448. $where .= " GROUP BY $tableposts.ID";
  449. $request = " SELECT $distinct * FROM $tableposts $join WHERE 1=1".$where." ORDER BY post_$orderby $limits";
  450.  
  451.  
  452. if ($preview) {
  453.     $request = 'SELECT 1-1'; // dummy mysql query for the preview
  454.     // little funky fix for IEwin, rawk on that code
  455.     $is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT)));
  456.     if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) {
  457.         $preview_content =  preg_replace('/\%u([0-9A-F]{4,4})/e',  "'&#'.base_convert('\\1',16,10).';'", $preview_content);
  458.     }
  459. }
  460.  
  461. // error_log("$request");
  462. // echo $request;
  463. $posts = $wpdb->get_results($request);
  464.  
  465. // No point in doing all this work if we didn't match any posts.
  466. if ($posts) {
  467.     // Get the categories for all the posts
  468.     foreach ($posts as $post) {
  469.         $post_id_list[] = $post->ID;
  470.     }
  471.     $post_id_list = implode(',', $post_id_list);
  472.  
  473.     $dogs = $wpdb->get_results("SELECT DISTINCT
  474.         ID, category_id, cat_name, category_nicename, category_description, category_parent
  475.         FROM $tablecategories, $tablepost2cat, $tableposts
  476.         WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
  477.         
  478.     foreach ($dogs as $catt) {
  479.         $category_cache[$catt->ID][] = $catt;
  480.     }
  481.  
  482.     // Do the same for comment numbers
  483.     $comment_counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount
  484.         FROM $tableposts
  485.         LEFT JOIN $tablecomments ON ( comment_post_ID = ID  AND comment_approved =  '1')
  486.         WHERE post_status =  'publish' AND ID IN ($post_id_list)
  487.         GROUP BY ID");
  488.     
  489.     if ($comment_counts) {
  490.         foreach ($comment_counts as $comment_count) {
  491.             $comment_count_cache["$comment_count->ID"] = $comment_count->ccount;
  492.         }
  493.     }
  494.  
  495.     // Get post-meta info
  496.     if ( $meta_list = $wpdb->get_results("
  497.             SELECT post_id,meta_key,meta_value 
  498.             FROM $tablepostmeta 
  499.             WHERE post_id IN($post_id_list)
  500.             ORDER BY post_id,meta_key
  501.         ", ARRAY_A) ) {
  502.         
  503.         // Change from flat structure to hierarchical:
  504.         $post_meta_cache = array();
  505.         foreach ($meta_list as $metarow) {
  506.             $mpid = $metarow['post_id'];
  507.             $mkey = $metarow['meta_key'];
  508.             $mval = $metarow['meta_value'];
  509.             
  510.             // Force subkeys to be array type:
  511.             if (!isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]))
  512.                 $post_meta_cache[$mpid] = array();
  513.             if (!isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]))
  514.                 $post_meta_cache[$mpid]["$mkey"] = array();
  515.             
  516.             // Add a value to the current pid/key:
  517.             $post_meta_cache[$mpid][$mkey][] = $mval;
  518.         }
  519.     }
  520.  
  521.  
  522.     if (1 == count($posts)) {
  523.         if ($p || $name) {
  524.             $more = 1;
  525.             $single = 1;
  526.         }
  527.         if ($s && empty($paged)) { // If they were doing a search and got one result
  528.             if (!strstr($_SERVER['PHP_SELF'], 'wp-admin')) // And not in admin section
  529.                 header('Location: ' . get_permalink($posts[0]->ID));
  530.         }
  531.     }
  532. } // End if posts.
  533. ?>
  534.